﻿<?php
//header('Access-Control-Allow-Origin: http://www.baidu.com'); //设置http://www.baidu.com允许跨域访问
//header('Access-Control-Allow-Headers: X-Requested-With,X_Requested_With'); //设置允许的跨域header

date_default_timezone_set("Asia/Chongqing");
//error_reporting(E_ERROR);
header('Content-Type:text/html; charset=utf8');
include "public.php";

$q = ($_SERVER['REQUEST_METHOD']=="POST") ? $_POST : $_GET;


$action = @$q['action'];


$result = new RST();		          //待返回数据
$data = new OBJ();			      //真实数据部分


function error($msg){
    $result = new RST();		          //待返回数据
	$result->error=1;
    $result->message = "无效请求";
    echo urldecode(json_encode($result));
}

switch ($action) {
    /* 查询 */
    case 'getContent':
        $tempId = @$q['tempId'];
        $passwd = isset($q['passwd']) ? $q['passwd'] : null;
        
        include 'artView.php';
        $data = getContentPre($tempId, $passwd) ;
        break;
		
    /* 保存 */
    case 'save':
        $tempId = @$q['tempId'];
        $content =  htmlspecialchars(stripslashes(@$q['content']));
        $countPic = @$q['countPicture'];
        $title = @$q['title'];
        $addrs = GetAddr();
        
        //cout(json_encode($addrs));
        
        include "artSave.php";
        $data = Save($tempId, $content, $addrs, $title, $countPic);
        
		break;
		
	/* 保存 */
    case 'setting':
        $id = @$q['tempId'];
        $params = $q['params'];
        
        include "artSave.php";
        Setting($id, $params);
        
        break;
    /* 搜索 */
    case 'search':
        $src = @$q['src'];
        $filter = @$q['filter'];
        $page = @$q['page'];
        
        include 'artSearch.php';
        $data = Search($src, $filter, $page);
        
        break;
    /* 页数 */
    case 'test':
        $src = @$q['src'];
        $filter = @$q['filter'];
        
        include 'artSearch.php';
        $data = Search($src, $filter);
        
        break;
            
        
    default:
		error("服务器未受理");
        break;
}



$result->data = $data;

/* 输出结果 */
if (isset($_GET["callback"])) {
    if (preg_match("/^[\w_]+$/", $_GET["callback"])) {
		echo htmlspecialchars(@$_GET['callback']).'('.json_encode($result).')';		//urldecode
    } else {
		error("error param");
        //echo urldecode(json_encode($result));
    }
} else {
    // cout(json_encode($result));
    echo json_encode($result);
}

